<template>
	<view>
		<s-layout title="首页" navbar="custom" tabbar="/pages/index/index" :bgStyle="bgStyle" :navbarStyle="navigation"
			:showFloatButton="true">
			<s-block v-for="(item, index) in template" :key="index" :styles="item.setStyle.dataStyle">
				<s-block-item :type="item.type" :data="item.setStyle" :styles="item.setStyle.dataStyle" />
			</s-block>
			<!-- 广告模块 -->
			<s-popup-image />
		</s-layout>
	</view>
</template>

<script setup>
	import {
		computed,
		ref
	} from 'vue';
	import {
		onLoad,
		onPageScroll,
		onPullDownRefresh
	} from '@dcloudio/uni-app';

	import app from '/shop/store/app.js';

	import $router from '/shop/router/index.js';

	import $share from '/shop/platform/share.js';

	const loading = ref(false);
	// 隐藏原生tabBar
	uni.hideTabBar({
		fail: () => {},
	});
	const template = computed(() => {
		return app().template?.home;
	});

	const setup = computed(() => {

		return app().template?.setup;
	});

	const navigation = computed(() => {
		const navigation = app().template?.home.find(e => e.type === 'pageSetting').setStyle
		return navigation

		// return app().template.navigation;
	});

	const bgStyle = computed(() => {

		const bgStyle = app().template?.home.find(e => e.type === 'pageSetting').setStyle.background
		return bgStyle


	})

	onLoad((options) => {
		// #ifdef MP
		// 小程序识别二维码
		if (options.scene) {
			const sceneParams = decodeURIComponent(options.scene).split('=');
			options[sceneParams[0]] = sceneParams[1];
		}
		// #endif

		// 预览模板
		if (options.templateId) {
			app().init(options.templateId);
		}

		// 解析分享信息
		if (options.spm) {
			$share.decryptSpm(options.spm);
		}

		// 进入指定页面(完整页面路径)
		if (options.page) {
			$router.go(decodeURIComponent(options.page));
		}
	});
	onPullDownRefresh(async () => {
		loading.value = true;
		uni.showLoading({
			title: '正在刷新...',
			mask: true,
			fail: () => {
				uni.hideLoading();
			},
		});
		await app().init();
		setTimeout(function() {
			uni.stopPullDownRefresh();
			loading.value = false;
			uni.hideLoading();
		}, 1000);
	});

	onPageScroll(() => {});
</script>

<style lang="scss"></style>